package org.zbclan.bf2.rcon.common.shared;

import java.util.HashMap;
import java.util.Map;

import com.google.gwt.user.client.rpc.IsSerializable;

public class Bf2Object implements IsSerializable {

	public enum Properties {

		CREATE("create"),

		ABSOLUTE_POSITION("absolutePosition"),

		ROTATION("rotation"),

		SET_CONTROL_POINT_ID("setControlPointId"),

		LAYER("layer");

		private String key;

		private Properties(String key) {
			this.key = key;
		}

		@Override
		public String toString() {
			return key;
		}
	}

	private Map<String, Bf2Property> properties = new HashMap<String, Bf2Property>();

	// /**
	// * abitrary
	// */
	// private String create;
	//
	// /**
	// * in the form of -146.453/161.298/-268.604
	// */
	// private String absolutePosition;
	//
	// /**
	// * in the form of 0.000/0.000/0.000
	// */
	// private String rotation;
	//
	// /**
	// * arbitrary
	// */
	// private String setControlPointId;
	//
	// /**
	// * 2, 3, 4, 5, and 6
	// */
	// private String layer;

	/**
	 * (customized) whether to include in game this object, or comment it out
	 */
	private boolean enabled;

	public String getCreate() {
		return getValue(Properties.CREATE.toString());
	}

	// public void setCreate(String create) {
	// this.create = create;
	// }
	//
	public String getAbsolutePosition() {
		return getValue(Properties.ABSOLUTE_POSITION.toString());
	}

	// public void setAbsolutePosition(String absolutePosition) {
	// this.absolutePosition = absolutePosition;
	// }

	public String getRotation() {
		return getValue(Properties.ROTATION.toString());
	}

	// public void setRotation(String rotation) {
	// this.rotation = rotation;
	// }

	public String getSetControlPointId() {
		return getValue(Properties.SET_CONTROL_POINT_ID.toString());
	}

	// public void setSetControlPointId(String setControlPointId) {
	// this.setControlPointId = setControlPointId;
	// }

	public String getLayer() {
		return getValue(Properties.LAYER.toString());
	}

	// public void setLayer(String layer) {
	// this.layer = layer;
	// }

	private String getValue(String key) {

		String value = null;

		Bf2Property p = properties.get(key);
		if (p != null) {
			value = p.getValue();
		}

		if (value == null) {
			value = "";
		}

		return value;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public Map<String, Bf2Property> getProperties() {
		return properties;
	}

	public void addProperty(Bf2Property p) {
		p.setEnabled(true);
		properties.put(p.getName(), p);
	}

	public void addDisabledProperty(Bf2Property p) {
		p.setEnabled(false);
		properties.put(p.getName(), p);
	}
}
